Skip to content

Complete CFF table parser with Type 2 CharString interpreter#25

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/complete-cff-table-parser
Draft

Complete CFF table parser with Type 2 CharString interpreter#25
Copilot wants to merge 5 commits intomainfrom
copilot/complete-cff-table-parser

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 16, 2025

The CFF table parser could read basic metadata but not extract glyphs. This adds full glyph parsing for CFF/OpenType fonts.

Changes

Extended CFF parser (tables/cff.ts)

  • Read CharStrings INDEX, Private DICT, Local Subr INDEX, and charset
  • Implement Type 2 CharString interpreter with stack-based execution
  • Support all path construction operators (moveto, lineto, rrcurveto, hhcurveto, vvcurveto, etc.)
  • Handle subroutine calls (callsubr/callgsubr) with proper bias calculation
  • Parse width from CharStrings and calculate bounding boxes

Integrated CFF into Font class (font.ts)

  • Add getCffGlyph() method for CFF fonts
  • Modify getGlyph() to auto-detect font type (CFF vs TrueType)
  • Convert CFF cubic bezier curves to TrueType-compatible Point[] format

Example usage:

const font = new Font(cffFontData)
const glyph = font.getGlyph(42)  // Now works for both CFF and TrueType fonts
// Returns GlyphEnriched with points[], bounds, and advanceWidth

Tested with unit tests covering line drawing, curves, width handling, and bounds calculation.

Original prompt

This section details on the original issue you should resolve

<issue_title>Complete cff table parser</issue_title>
<issue_description>I started implementing the cff table parser but it can't fully parse it into glyphs yet.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits November 16, 2025 02:55
- Extended CFF parser to read CharStrings INDEX, Private DICT, Local Subr INDEX, and charset
- Implemented Type 2 CharString interpreter with support for all major path construction operators
- Added getCffGlyph method to Font class to parse CFF glyphs
- Converted CFF cubic bezier paths to Point[] format compatible with TrueType
- Updated getGlyph to detect and handle both TrueType (glyf) and CFF fonts

Co-authored-by: bschlenk <1390303+bschlenk@users.noreply.github.com>
- Tests for simple line drawing (horizontal and vertical)
- Tests for curve drawing (rrcurveto)
- Tests for width handling
- Tests for bounds calculation

Co-authored-by: bschlenk <1390303+bschlenk@users.noreply.github.com>
Co-authored-by: bschlenk <1390303+bschlenk@users.noreply.github.com>
Co-authored-by: bschlenk <1390303+bschlenk@users.noreply.github.com>
Copilot AI changed the title [WIP] Complete cff table parser functionality Complete CFF table parser with Type 2 CharString interpreter Nov 16, 2025
Copilot AI requested a review from bschlenk November 16, 2025 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete cff table parser

2 participants